home *** CD-ROM | disk | FTP | other *** search
- // Source Code generated by PatchMaker 1.1
- // a sick idea by Paul Baxter
- //
- // paul@paulbaxter.com
-
- #if TARGET_CPU_68K && !TARGET_RT_MAC_CFM
- #error Sorry Can't do that
- #endif
-
- #include <MixedMode.h>
- #include <Appearance.h>
- #include <SpeechSynthesis.h>
- #include <A4Stuff.h>
- #include <stdio.h>
-
-
- // enums for routinedescriptor
- enum {
- uppAlertProcInfo_0_0 = kPascalStackBased
- | RESULT_SIZE(kTwoByteCode)
- | STACK_ROUTINE_PARAMETER(1,kTwoByteCode)
- | STACK_ROUTINE_PARAMETER(2,kFourByteCode),
- uppAlertProcInfo_1_0 = kPascalStackBased
- | RESULT_SIZE(kTwoByteCode)
- | STACK_ROUTINE_PARAMETER(1,kTwoByteCode)
- | STACK_ROUTINE_PARAMETER(2,kFourByteCode),
- uppNMInstallProcInfo = kRegisterBased
- | REGISTER_RESULT_LOCATION(kRegisterD0)
- | RESULT_SIZE(kTwoByteCode)
- | REGISTER_ROUTINE_PARAMETER(1,kRegisterD1,kTwoByteCode)
- | REGISTER_ROUTINE_PARAMETER(2,kRegisterA0,kFourByteCode),
- uppPatchExtraInfo // not used
- };
-
- // Function Prototypes
- extern pascal short myAlert_0_0Patch(short param1, long param2);
- extern pascal short myAlert_1_0Patch(short param1, long param2);
- extern pascal short myAlertPatch(short param1, long param2);
- extern pascal short myNMInstallPatch(short param1, long param2);
-
- extern void LoadStrings(void);
- extern void InstallGestalt(void);
-
- // Globals to hold original routine descriptors
- RoutineDescriptorPtr gOriginalAlert_0_0 = nil;
- RoutineDescriptorPtr gOriginalAlert_1_0 = nil;
- RoutineDescriptorPtr gOriginalNMInstall = nil;
-
- SInt16 gJustDoItActivated = false;
-
-
- #define kJustDoItGestalt 'Nike'
-
- #define kMagicAreYouSureAlertID 2212
- #define kFinderSig 'MACS'
-
- #define kStringList 128
- enum {
- eBringFindertoFront = 1,
- eAllocationErr = 2
- };
-
- Str255 gPleaseBringFindertoFront, gErrString;
-
- void BringApppSigtoFront(ResType sig);
-
- // Tell MetroWerks the procInfo for main
- ProcInfoType __procinfo = kPascalStackBased;
- pascal void main(void)
- {
- RoutineDescriptorPtr originaldesc, newdesc, unImplimentedTrapAddr;
- UInt32 size;
- UInt16 index;
- THz theZone;
-
- // get globals
- EnterCodeResource();
- // detach ourselves
- DetachResource(Get1Resource('INIT', 0));
-
- // make sure we are in the system heap
- theZone = GetZone();
- SetZone(SystemZone());
-
- // Load strings MUST HAPPEN BERFORE TRAP IS PATCHED
- LoadStrings();
-
- InstallGestalt();
-
- unImplimentedTrapAddr = NGetTrapAddress(_Unimplemented, (_Unimplemented & 0x0800) ? ToolTrap : OSTrap);
-
- originaldesc = NGetTrapAddress(_Alert, (_Alert & 0x0800) ? ToolTrap : OSTrap);
- if (originaldesc != unImplimentedTrapAddr) {
- if (originaldesc->goMixedModeTrap != _MixedModeMagic) {
- // Trap is 68K
- size = sizeof(RoutineDescriptor) + (sizeof(RoutineRecord) * 1);
- // allocate new descriptor
- newdesc = (RoutineDescriptorPtr) NewPtrSys(size);
- if (!newdesc) {
- DebugStr(gErrString);
- return;
- }
- // set fields of routine decscriptor
- newdesc->goMixedModeTrap = _MixedModeMagic;
- newdesc->version = 7;
- newdesc->routineDescriptorFlags = 0;
- newdesc->reserved1 = 0;
- newdesc->reserved2 = 0;
- newdesc->selectorInfo = 0;
- newdesc->routineCount = 1;
- index = 0;
- gOriginalAlert_0_0 = originaldesc;
- newdesc->routineRecords[index].procInfo = uppAlertProcInfo_0_0;
- newdesc->routineRecords[index].reserved1 = 0;
- newdesc->routineRecords[index].ISA = GetCurrentArchitecture();
- newdesc->routineRecords[index].routineFlags = 0;
- newdesc->routineRecords[index].procDescriptor = (ProcPtr)myAlert_0_0Patch;
- newdesc->routineRecords[index].reserved2 = 0;
- newdesc->routineRecords[index].selector = 0;
- index = 1;
- gOriginalAlert_1_0 = originaldesc;
- newdesc->routineRecords[index].procInfo = uppAlertProcInfo_1_0;
- newdesc->routineRecords[index].reserved1 = 0;
- newdesc->routineRecords[index].ISA = GetCurrentArchitecture();
- newdesc->routineRecords[index].routineFlags = 0;
- newdesc->routineRecords[index].procDescriptor = (ProcPtr)myAlert_1_0Patch;
- newdesc->routineRecords[index].reserved2 = 0;
- newdesc->routineRecords[index].selector = 0;
- }
- else {
- // Trap is PPC
- size = sizeof(RoutineDescriptor) + (sizeof(RoutineRecord) * originaldesc->routineCount);
- newdesc = (RoutineDescriptorPtr) NewPtrSys(size);
- if (!newdesc) {
- DebugStr(gErrString);
- return;
- }
- BlockMoveData(originaldesc, newdesc, size);
- for (index = 0; index <= newdesc->routineCount; index++) {
- if ((originaldesc->routineRecords[index].selector == 0) &&
- (originaldesc->routineRecords[index].ISA == 0) && (originaldesc->routineRecords[index].procInfo == uppAlertProcInfo_0_0)) {
- gOriginalAlert_0_0= NewRoutineDescriptor(originaldesc->routineRecords[index].procDescriptor,
- uppAlertProcInfo_0_0, originaldesc->routineRecords[index].ISA);
- newdesc->routineRecords[index].procDescriptor = (ProcPtr)myAlert_0_0Patch;
- newdesc->routineRecords[index].ISA = GetCurrentArchitecture();
- continue;
- }
- if ((originaldesc->routineRecords[index].selector == 0) &&
- (originaldesc->routineRecords[index].ISA == 1) && (originaldesc->routineRecords[index].procInfo == uppAlertProcInfo_1_0)) {
- gOriginalAlert_1_0= NewRoutineDescriptor(originaldesc->routineRecords[index].procDescriptor,
- uppAlertProcInfo_1_0, originaldesc->routineRecords[index].ISA);
- newdesc->routineRecords[index].procDescriptor = (ProcPtr)myAlert_1_0Patch;
- newdesc->routineRecords[index].ISA = GetCurrentArchitecture();
- continue;
- }
- }
- }
- NSetTrapAddress((UniversalProcPtr) newdesc, _Alert, (_Alert & 0x0800) ? ToolTrap : OSTrap);
- }
-
- originaldesc = NGetTrapAddress(_NMInstall, (_NMInstall & 0x0800) ? ToolTrap : OSTrap);
- if (originaldesc != unImplimentedTrapAddr) {
- if (originaldesc->goMixedModeTrap != _MixedModeMagic) {
- // Trap is 68K
- size = sizeof(RoutineDescriptor) + (sizeof(RoutineRecord) * 0);
- // allocate new descriptor
- newdesc = (RoutineDescriptorPtr) NewPtrSys(size);
- if (!newdesc) {
- DebugStr(gErrString);
- return;
- }
- // set fields of routine decscriptor
- newdesc->goMixedModeTrap = _MixedModeMagic;
- newdesc->version = 7;
- newdesc->routineDescriptorFlags = 0;
- newdesc->reserved1 = 0;
- newdesc->reserved2 = 0;
- newdesc->selectorInfo = 0;
- newdesc->routineCount = 0;
- index = 0;
- gOriginalNMInstall = originaldesc;
- newdesc->routineRecords[index].procInfo = uppNMInstallProcInfo;
- newdesc->routineRecords[index].reserved1 = 0;
- newdesc->routineRecords[index].ISA = GetCurrentArchitecture();
- newdesc->routineRecords[index].routineFlags = 4;
- newdesc->routineRecords[index].procDescriptor = (ProcPtr)myNMInstallPatch;
- newdesc->routineRecords[index].reserved2 = 0;
- newdesc->routineRecords[index].selector = 0;
- }
- else {
- // Trap is PPC
- size = sizeof(RoutineDescriptor) + (sizeof(RoutineRecord) * originaldesc->routineCount);
- newdesc = (RoutineDescriptorPtr) NewPtrSys(size);
- if (!newdesc) {
- DebugStr(gErrString);
- return;
- }
- BlockMoveData(originaldesc, newdesc, size);
- gOriginalNMInstall = originaldesc;
- index = 0;
- newdesc->routineRecords[index].procDescriptor = (ProcPtr)myNMInstallPatch;
- newdesc->routineRecords[index].ISA = GetCurrentArchitecture();
- }
- NSetTrapAddress((UniversalProcPtr) newdesc, _NMInstall, (_NMInstall & 0x0800) ? ToolTrap : OSTrap);
- }
-
- // restore to original heap
- SetZone(theZone);
- // restore globals
- ExitCodeResource();
- }
-
- void InstallGestalt(void)
- {
- OSErr err = NewGestaltValue(kJustDoItGestalt, (long) &gJustDoItActivated);
- }
-
- pascal short myAlert_0_0Patch(short param1, long param2)
- {
- short result;
- // Get globals
- EnterCodeResource();
-
- result = myAlertPatch( param1, param2);
-
- // Release globals
- ExitCodeResource();
- return result;
- }
-
- pascal short myAlert_1_0Patch(short param1, long param2)
- {
- short result;
- // Get globals
- EnterCodeResource();
-
- result = myAlertPatch( param1, param2);
-
- // Release globals
- ExitCodeResource();
- return result;
- }
-
- pascal short myAlertPatch(short param1, long param2)
- {
- short result;
- // Get globals
- EnterCodeResource();
-
- if ((gJustDoItActivated == false) || (param1 != kMagicAreYouSureAlertID)) {
- result = CALL_TWO_PARAMETER_UPP( gOriginalAlert_1_0, uppAlertProcInfo_1_0, param1, param2);
- }
- else {
- result = ok;
- }
-
- // Release globals
- ExitCodeResource();
- return result;
- }
-
- pascal short myNMInstallPatch(short param1, long param2)
- {
- short result;
- // Get globals
- EnterCodeResource();
-
-
- result = CallOSTrapUniversalProc(gOriginalNMInstall, uppNMInstallProcInfo, param1, param2);
- if (gJustDoItActivated != false) {
- NMRecPtr theNMRec = (NMRecPtr)param2;
- ProcessSerialNumber PSN;
-
- if (theNMRec->nmStr && EqualString(theNMRec->nmStr, gPleaseBringFindertoFront, false, false)) {
- BringApppSigtoFront(kFinderSig);
- }
- }
-
- // Release globals
- ExitCodeResource();
- return result;
- }
-
- void BringApppSigtoFront(ResType sig)
- {
- ProcessSerialNumber PSN = {0, kNoProcess};
- ProcessInfoRec info = {
- sizeof(ProcessInfoRec),
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0};
-
-
- while (!GetNextProcess(&PSN)) {
- if (!GetProcessInformation(&PSN,&info)) {
- if (sig == info.processSignature) {
- SetFrontProcess(&PSN);
- return;
- }
- }
- }
- }
-
-
- void LoadStrings(void)
- {
- GetIndString(gPleaseBringFindertoFront, kStringList, eBringFindertoFront);
- GetIndString(gErrString, kStringList, eAllocationErr);
- }
-